package ModelLayer;

import android.graphics.Point;

public class RoomCharacter {
	public Point pixelPosition = new Point(); 
	public Point tilePosition = new Point();
	public Room room;
	private int facingDirection;
	public boolean firstX = false;
	public boolean firstY = false;

	private int pixelDelta;
	
	public RoomCharacter(Room currentRoom){
		room = currentRoom;
		Point start = room.getStartPosition();
		if (start.x!=0 || start.y!=0)
			tilePosition = start;
		else {
			tilePosition.x = 2;
			tilePosition.y = 2;
		}
		pixelPosition.x = tilePosition.x*32;
		pixelPosition.y = tilePosition.y*32;
		facingDirection = Direction.DOWN;
		
		pixelDelta = 2;
	} 
	
	public void move(int direction){
		facingDirection = direction;
			switch(direction){
				case Direction.UP:
					pixelPosition.y -= pixelDelta;
					break;
				case Direction.DOWN:
					pixelPosition.y += pixelDelta;
					break;
				case Direction.LEFT:
					pixelPosition.x -= pixelDelta;
					break;
				case Direction.RIGHT:
					pixelPosition.x += pixelDelta;
					break;
			}
	}
	
	public Room getCurrentRoom() {
		return room;
	}

	public void setCurrentRoom(Room currentRoom) {
		this.room = currentRoom;
	}

	public void setFacingDirection(int facingDirection) {
		this.facingDirection = facingDirection;
	}

	public int getFacingDirection() {
		return facingDirection;
	}
	
	public void setTilePosition(Point position){
		tilePosition = position;
		pixelPosition.x = position.x*32;
		pixelPosition.y = position.y*32;
	}

	public Point getTilePosition() {
		return tilePosition;
	}
	
	public void changeTilePosition(int direction){
		switch(direction){
		case Direction.UP:
			tilePosition.y--;
			firstY = !firstY; 
			break;
		case Direction.DOWN:
			tilePosition.y++;
			firstY = !firstY;
			break;
		case Direction.LEFT:
			tilePosition.x--;
			firstX = !firstX;
			break;
		case Direction.RIGHT:
			firstX = !firstX;
			tilePosition.x++;
			break;
		}
	}
}
